package thread05;

/**
 * 线程第三种创建方式:匿名内部类
 * 格式:
 *  new 父类/父接口(){
 *      //重写父类或父接口中的方法
 *  }
 *
 */
public class ThreadDemo01 {
    public static void main(String[] args) {
        //method01();
        /**
         *  class 类名 implements Runnable{
         * 	  public void run(){
         * 		  //定义线程要执行的任务
         *            }
         *   }
         *    new Thread(new 类名()).start();
         */
  /*      Runnable task01 = new Runnable(){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "..." + i);
                }
            }
        };

        new Thread(task01).start();*/

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "..." + i);
                }
            }
        }).start();

        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "..." + i);
        }


    }

    private static void method01() {
        /**
         *   class 类名 extends Thread{
         * 	  public void run(){
         * 	  	//定义线程要执行的任务
         *       }
         *   }
         */
    /*     Thread t = new Thread() {
             @Override
             public void run() {
                 for (int i = 0; i < 10; i++) {
                     System.out.println(Thread.currentThread().getName() + "..." + i);
                 }
             }
         };
         t.start();*/

        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "..." + i);
                }
            }
        }.start();


        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "..." + i);
        }
    }
}
